package norm.reference

class ComparisonGroup {

	long id
	String name
	Date dateCreated
	int normReferenced = 0
	ArrayList<int[]> responseCounts
	
	static hasMany = [cdfs:CDF, departmentFilters:Department, divisionFilters:Division, courseFilters:Course]
	
    static constraints = {
		name(blank:false)
		dateCreated(blank:false)
		normReferenced(blank:false)
	}
	
	static mapping = {
		table "NORM_comparisongroup"
	}
	
	int calculateRowSum()
	{
		int sum = 0
		for(int i = 0; i<5; i++)
		{
			sum += responseCounts[i]
		}
		
		return sum
	}	
	
	String toString()
	{
		return name
	}
	
	void initializeList()
	{
		if(responseCounts == null)
		{
			responseCounts = new ArrayList<int[]>()
			for(i in 0..23)
			{
				responseCounts.add([0,0,0,0,0])
			}
		}	
		
	}
	
	String divisionFiltersToString()
	{
		String output = "("
		divisionFilters.each() {output+= " $it ,"	}
		output+= ")"
		return output
	}
	
	String departmentFiltersToString()
	{
		String output = "("
		departmentFilters.each() {output+= "\' $it \',"	}
		output+= ")"
	}
	
	String courseFiltersToString()
	{
		String output = "("
		courseFilters.each() {output+= "\' $it \',"	}
		output+= ")"
	}
}
